﻿using Blackthorn.Data.EntityFramework;
using Blackthorn.Data.EntityFramework.Repositories;
using Blackthorn.Data.Repository;
using Blackthorn.Data.UnitOfWork;
using Demo.Data.EntityFramework.Model;
using Demo.Data.Model;
using Demo.Data.Repositories.Orders;

namespace Demo.Data.EntityFramework
{
    public static class RepositoriesManager
    {
        private static readonly IDataUnitOfWork _unitOfWork;

        static RepositoriesManager()
        {
            _unitOfWork = new EntitiesUnitOfWork(new LocalDatabaseEntities());
            _unitOfWork.RegisterRepository<ICustomer, EntitiesRepository<ICustomer,Customer>>();
            _unitOfWork.RegisterRepository<IOrder, EntitiesRepository<IOrder,Order>>();
        }

        /// <summary>
        /// Gets Customers EntitiesRepository.
        /// </summary>
        public static IDataRepository<ICustomer> Customers
        {
            get { return _unitOfWork.GetRepository<ICustomer>(); }
        }

        /// <summary>
        /// Gets Orders EntitiesRepository.
        /// </summary>
        public static IOrdersRepository Orders
        {
            get { return (IOrdersRepository) _unitOfWork.GetRepository<IOrder>(); }
        }

        public static bool HasUnsavedChanges
        {
            get { return _unitOfWork.HasUnsavedChanges; }
        }

        public static void SaveChanges()
        {
           _unitOfWork.SaveChanges();
        }
    }
}
